<?php

namespace App\Kuafu\Order\Command;

use App\Kuafu\Base\Command\Traits\KfGetTimeInterval;
use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\CouponExt\Enum\CouponExtEnum;
use App\Kuafu\Order\Enum\CodeEnum;
use App\Kuafu\Order\Model\OrderAbnormalityModel;
use App\Kuafu\Order\Model\OrderCouponSplitModel;
use App\Kuafu\Order\Model\OrderSplitModel;
use App\Kuafu\Order\Model\OrderStatisticalModel;
use App\Kuafu\Order\Service\OrderService;
use App\Kuafu\Shop\Service\ShopService;
use App\Library\FeiShu\SendFs;
use Illuminate\Console\Command;

class OrderAbnormality extends Command
{
    use KfGetTimeInterval;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'order:sync-abnormality-order {--d=false :  是否直接执行 示例.true - 默认执行前一天数据 false - 交互式执行} {--debug=false}';

    /**
     * The console command description.
     *
     * @var string
     */

    protected $description = '夸父堂食订单自检且自修';


    /**
     * 异常订单列表
     *
     * @var array
     */
    protected array $errorOrder = [];

    private const ERROR_REASON_DISH_DATA_ERROR                   = 500011;
    private const ERROR_REASON_PAY_STREAM_ERROR                  = 500012;
    private const ERROR_REASON_ORDER_ORIGIN_PAY_PRICE_ERROR      = 500013;
    private const ERROR_REASON_ORDER_ORIGIN_REAL_PAY_PRICE_ERROR = 500014;
    private const ERROR_REASON_ORDER_PAY_PRICE_ERROR             = 500015;
    private const ERROR_REASON_ORDER_REFUND_PRICE_ERROR          = 500016;
    private const ERROR_REASON_ORDER_DISCOUNT_PRICE_ERROR        = 500017;
    private const ERROR_REASON_ORDER_COST_PRICE_ERROR            = 500018;

    private const ERROR_REASON_ORDER_DETAIL_ORIGIN_PRICE_ERROR = 500031;
    private const ERROR_REASON_ORDER_DETAIL_DISCOUNT_ERROR     = 500032;
    private const ERROR_REASON_ORDER_DETAIL_PAY_PRICE_ERROR    = 500033;

    private const ERROR_REASON_TEXT = [
        self::ERROR_REASON_DISH_DATA_ERROR                   => '菜品明细缺失',
        self::ERROR_REASON_PAY_STREAM_ERROR                  => '支付明细缺失',
        self::ERROR_REASON_ORDER_ORIGIN_PAY_PRICE_ERROR      => '[用户]主订单支付金额异常',
        self::ERROR_REASON_ORDER_ORIGIN_REAL_PAY_PRICE_ERROR => '[财务]主订单支付金额异常',
        self::ERROR_REASON_ORDER_PAY_PRICE_ERROR             => '订单支付金额与用户不匹配',
        self::ERROR_REASON_ORDER_REFUND_PRICE_ERROR          => '订单退款金额有误',
        self::ERROR_REASON_ORDER_DISCOUNT_PRICE_ERROR        => '订单优惠券优惠金额计算有误',
        self::ERROR_REASON_ORDER_COST_PRICE_ERROR            => '订单优惠券成本金额计算有误',

        self::ERROR_REASON_ORDER_DETAIL_ORIGIN_PRICE_ERROR => '订单商品原价计算有误',
        self::ERROR_REASON_ORDER_DETAIL_DISCOUNT_ERROR     => '订单商品优惠金额计算有误',
        self::ERROR_REASON_ORDER_DETAIL_PAY_PRICE_ERROR    => '订单商品实收计算金额有误',
    ];

    private array $statisticalData = [];
    private bool  $debug           = true;
    private bool  $isStoreDb       = true; // 受 debug 影响 && 是否入库
    private array $debugShopId     = []; // 受 debug 影响 && 手动调试门店 ID
    private array $debugOrderId    = []; // 受 debug 影响 && 手动调试订单 ID

    private array $shopList = [];

    private array $orderShopList = [];

    private array $num = [
        'errorNum' => 0,   // 异常订单总量
        'totalNum' => 0,   // 总订单量
        'shopNum'  => 0,   // 在线店铺数量

        'offlineTotalNum' => 0, // 离线订单总量
        'offlineShopNum'  => 0, // 离线门店数量
    ];

    /**
     * Execute the console command
     *
     * @return int
     */
    public function handle()
    {
        $this->debug        = $this->option('debug') == 'true';
        $this->debugShopId  = [15385];
        $this->debugOrderId = ['290747282586862259'];
        $skipShopList       = [13315]; // 跳过的 店铺id
        // TODO XM 记得下次修复 统计表的时间问题
        if ($this->debug) {
            list($startTimeAt, $endTimeAt) = [strtotime('2023-10-23'), strtotime('2023-10-25')]; // 2022-01-01 - time()
        } else {
            list($startTimeAt, $endTimeAt) = $this->getTimeInterval();
        }


        $this->info('**************** 开始执行脚本 ****************');
        $this->info(vsprintf(
            '起始时间 [ %s ] 截止时间 [ %s ]',
            [date('Y-m-d H:i:s', $startTimeAt), date('Y-m-d H:i:s', $endTimeAt)]
        ));

        try {

            if (!$this->debug) {
                OrderAbnormalityModel::query()
                                     ->whereBetween('createdAt', [$startTimeAt, $endTimeAt])
                                     ->delete();
            }

            $initArr = [];
            if ($this->debug && !empty($this->debugShopId)) {
                $initArr = $this->debugShopId;
            } else {
                for ($i = 0; $i <= 99; $i++) {
                    $initArr[] = $i;
                }
            }


            // 获取以下内容的订单
            foreach ($initArr as $i) {
                $this->errorOrder = []; // 重置

                // 为payStreamRel服务
                (new BaseModel())->setSplitShopId($i);

                OrderSplitModel::suffix($i)->query()
                               ->when($this->debug && !empty($this->debugShopId), function ($query) {
                                   $query->whereIn('shopId', $this->debugShopId);
                               })
                               ->when($this->debug && !empty($this->debugOrderId), function ($query) {
                                   $query->whereIn('orderId', $this->debugOrderId);
                               })
                               ->whereNotIn('shopId', $skipShopList)
                               ->whereIn('orderStatus',
                                   [CodeEnum::ORDER_STATUS_FINISHED])
                               ->with('orderDetailRel')
                               ->with([
                                   'orderCouponExtRel' => function ($query) {
                                       $query->where('couponExtStatus',
                                           CouponExtEnum::COUPON_STATUS_USED);
                                   }
                               ])
                               ->with([
                                   'orderDiscountRel' => function ($query) {
                                       $query->where('discountType', '!=',
                                           CodeEnum::ORDER_DISCOUNT_TYPE_CUSTOM_PAY);
                                   }
                               ])
                               ->with([
                                   'orderCouponRel' => function ($query) {
                                       $query->whereIn('status',
                                           [
                                               OrderCouponSplitModel::STATUS_USED,
                                               OrderCouponSplitModel::STATUS_WAIT
                                           ]);
                                   }
                               ])
                               ->with('orderExtRel')
                               ->with([
                                   'orderPayStreamRel' => function ($query) {
                                       $query->where('payStatus', 1);
                                   },
                                   'orderPayStreamRel.streamCustomPaymentRel'
                               ])
                               ->with([
                                   'orderRefundStreamRel' => function ($query) {
                                       $query->where('refundStatus', 2);
                                   },
                                   'orderRefundStreamRel.streamCustomPaymentRel'
                               ])
                               ->orderBy('orderId', 'desc')
                               ->whereBetween('completeTime', [$startTimeAt, $endTimeAt])
                               ->chunk(500, function ($orders) {
                                   foreach ($orders as $order) {
//                                       dd($order);

                                       /* 数据统计 */
                                       $this->handleShop($order);
                                       /* 数据统计 */

                                       /**
                                        * 校验数据
                                        */
                                       $this->checkOrder($order);
                                   }
                               });

                // 处理异常订单
                if ($this->debug === false && $this->isStoreDb === true) {
                    collect($this->errorOrder)->chunk(500)->each(function ($item) {
                        OrderAbnormalityModel::query()->insert($item->toArray());
                    });
                }
                $this->info('当前循环表 :' . $i);
            }

            $this->num['shopNum']        = count($this->shopList);
            $this->num['offlineShopNum'] = $this->getOfflineShopNum();

            $this->sendFs();
            $this->insertStatisticalDb();


        } catch (\Exception $exception) {
            SendFs::newRobot()
                  ->setTitleContent('[' . date('Y-m-d H:i:s') . '] : ' . 'Order Abnormality 服务报错了, 需要重新执行',
                      $exception)->send();
        }
    }

    public static function getInsertOrderData($order, $reason)
    {
        return [
            'brandId'           => $order->brandId,
            'platformId'        => $reason . ':' . self::ERROR_REASON_TEXT[$reason],
            'shopId'            => $order->shopId,
            'userId'            => $order->userId,
            'sourceType'        => $order->sourceType,
            'serialNum'         => $order->serialNum,
            'remark'            => $order->remark,
            'createdAt'         => $order->createdAt->timestamp,
            'createdByUid'      => $order->createdByUid,
            'createdBy'         => $order->createdBy,
            'orderId'           => $order->orderId,
            'originalPrice'     => $order->originalPrice,
            'shouldPrice'       => $order->shouldPrice,
            'payPrice'          => $order->payPrice,
            'realPayPrice'      => $order->realPayPrice,
            'refundStatus'      => $order->refundStatus,
            'payChannel'        => $order->payChannel,
            'payStatus'         => $order->payStatus,
            'orderStatus'       => $order->orderStatus,
            'completeTime'      => $order->completeTime,
            'refundMoney'       => $order->refundMoney,
            'orderShouldPrice'  => $order->orderShouldPrice,
            'discountPrice'     => $order->discountPrice,
            'couponPrice'       => $order->couponPrice,
            'couponCostPrice'   => $order->couponCostPrice,
            'realDiscountPrice' => $order->realDiscountPrice,
            'updatedByUid'      => $order->updatedByUid,
            'updatedBy'         => $order->updatedBy,
            'updatedAt'         => $order->updatedAt->timestamp,
        ];
    }

    public function insertOrder($order, $reason)
    {
        if ($this->debug) {
            $this->info('shopId:' . $order->shopId . '-' . $reason . ':' . self::ERROR_REASON_TEXT[$reason]);
            die;
        }
        array_push($this->errorOrder, self::getInsertOrderData($order, $reason));

        // 统计订单数据
        $this->insertStaticData($reason);

    }

    public function insertStaticData($tag)
    {
        if (empty($this->statisticalData[$tag])) {
            $this->statisticalData[$tag] = 1;
        } else {
            $this->statisticalData[$tag] += 1;
        }
        $this->incErrorNum();
    }

    public function incErrorNum()
    {
        $this->num['errorNum']++;
    }

    public function sendFs()
    {
        $maxShop = $this->getMaxOnlineNumShopId();

        if (empty($maxShop)) {
            return;
        }

        $offShopContent = $this->getFsOffLineShopModule();

        $content = <<<STR
昨日堂食总订单统计:
总有效订单量: {$this->num['totalNum']} 单
总有效店铺数: {$this->num['shopNum']} 家
总订单最大店铺: {$this->getShopField($maxShop['shopId'], 'name')}, 单量为: {$maxShop['orderNum']} 单
-------
$offShopContent
-------
昨日堂食异常统计:
STR;

        if ($this->num['errorNum'] > 0) {
            $content .= "共有" . $this->num['errorNum'] . '笔订单有疑问, 具体原因:' . PHP_EOL;
            foreach ($this->statisticalData as $key => $datum) {
                $content .= vsprintf("错误码 %s[%s]: %s 单" . PHP_EOL, [$key, self::ERROR_REASON_TEXT[$key], $datum]);
            }
        } else {
            $content .= '无订单异常, 昨日又是核平的一天';
        }

        if ($this->debug) {
            dump($content);
        } else {
            $duringTime = bcsub(microtime(true), LARAVEL_START, 2);
            SendFs::newRobot(SendFs::ROBOT_STATISTICAL)
                  ->setTitleContent('堂食订单自查 BOT (' . $duringTime . '秒) ' . '[' . date('Y-m-d H:i:s') . ']',
                      $content)->send();
        }
    }

    private function handleShop($order)
    {
        // 总订单量
        $this->num['totalNum']++;

        $keyList = [
            OrderStatisticalModel::ORDER_STATISTICAL_TYPE_EAT_IN,
            OrderStatisticalModel::ORDER_STATISTICAL_TYPE_IN_APPLET
        ];

        foreach ($keyList as $typeItem) {
            $this->handleTypeOne($order, $typeItem);
        }
    }

    private function handleTypeOne($order, $type)
    {
        if (empty($this->shopList[$order->shopId][$type])) {
            $this->shopList[$order->shopId][$type] = self::initDataFormat($order->shopId, $order->completeTime);
        }

        switch ($type) {
            case  OrderStatisticalModel::ORDER_STATISTICAL_TYPE_EAT_IN:
                break;
            case  OrderStatisticalModel::ORDER_STATISTICAL_TYPE_IN_APPLET:
                if ($order->sourceType != CodeEnum::SOURCE_TYPE_MINI) {
                    return;
                }
                break;
        }

        $shopData = $this->shopList[$order->shopId][$type];

        $shopData['orderNum']++;
        // 判断离线
        if ($order->offOrderId != 0) {
            $this->num['offlineTotalNum']++;
            $shopData['offlineOrderNum']++;
        }

        // 统计订单数据
        $shopData['originalPrice']             += $order->originalPrice;
        $shopData['payPrice']                  += $order->payPrice;
        $shopData['realPayPrice']              += $order->realPayPrice;
        $shopData['discountPrice']             = $shopData['originalPrice'] - $shopData['payPrice'];
        $this->shopList[$order->shopId][$type] = $shopData;
    }

    private function initDataFormat(string $shopId, int $completeTime): array
    {
        return [
            'shopId'          => $shopId, // shopId
            'orderNum'        => 0, // 订单量
            'offlineOrderNum' => 0, // 离线订单量
            'originalPrice'   => 0, // 订单原价
            'discountPrice'   => 0, // 订单优惠
            'payPrice'        => 0, // 订单实收
            'realPayPrice'    => 0, // 订单实收
            'time'            => strtotime(date('Y-m-d', $completeTime))
        ];
    }

    public function insertStatisticalDb()
    {
        $insertData = [];
        foreach ($this->shopList as $typeOne) {
            foreach ($typeOne as $type => $item) {
                $insertData[] = [
                    'shopId'        => $item['shopId'],
                    'offNum'        => $item['offlineOrderNum'],
                    'num'           => $item['orderNum'],
                    'originalPrice' => $item['originalPrice'],
                    'discountPrice' => $item['discountPrice'],
                    'payPrice'      => $item['payPrice'],
                    'realPayPrice'  => $item['realPayPrice'],
                    'time'          => $item['time'],
                    'type'          => $type
                ];
            }
        }

        if (true || ($this->debug === false && $this->isStoreDb === true)) {
            OrderStatisticalModel::query()
                                 ->whereIn('shopId', array_column($insertData, 'shopId'))
                                 ->whereIn('time', array_column($insertData, 'time'))
                                 ->whereIn('type', array_column($insertData, 'type'))
                                 ->delete();

            collect($insertData)->chunk(500)->each(function ($item) {
                OrderStatisticalModel::query()->insert($item->toArray());
            });
        }

    }

    public function checkOrder($order)
    {
        // 判断 菜品数据 是否存在
        if (empty($order->orderDetailRel)) {
            $this->insertOrder($order, self::ERROR_REASON_DISH_DATA_ERROR);
            return;
        }

        // 判断 订单支付明细是否存在
        if (empty($order->orderPayStreamRel)) {
            $this->insertOrder($order, self::ERROR_REASON_PAY_STREAM_ERROR);
            return;
        }

        // 判断 原价 == [用户]支付金额 + 优惠金额
        if ($order->originalPrice != $order->payPrice + $order->discountPrice) {

            if ($this->debug) {
                dump([
                    'errorCalcFormat'     => 'order-OriginalPrice != order->PayPrice + order->DiscountPrice',
                    'shopId'              => $order->shopId,
                    'orderId'             => $order->orderId,
                    'order-OriginalPrice' => $order->originalPrice,
                    'order-PayPrice'      => $order->payPrice,
                    'order-DiscountPrice' => $order->discountPrice,
                    'total'               => $order->payPrice + $order->discountPrice,
                    'recommended'         => '无推荐操作'
                ]);
            }

            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_ORIGIN_PAY_PRICE_ERROR);
            return;
        }

        // 判断 原价 == [财务]支付金额 + 优惠金额
        if ($order->originalPrice != $order->realPayPrice + $order->realDiscountPrice) {

            if ($this->debug) {
                dump([
                    'orderId'            => $order->orderId,
                    'orderOriginalPrice' => $order->originalPrice,
                    'realPayPrice'       => $order->realPayPrice,
                    'realDiscountPrice'  => $order->realDiscountPrice,
                    'total'              => $order->realPayPrice + $order->realDiscountPrice
                ]);
            }

            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_ORIGIN_REAL_PAY_PRICE_ERROR);
            return;
        }

        // 组合支付退款流水
        $refundStream = clone $order->orderRefundStreamRel;

        $payStream = $order->orderPayStreamRel->each(function ($pay) use (
            $refundStream
        ) {
            $pay->validPayPrice = $pay->payPrice;
            $refundStream->each(function ($refund, $key) use (
                $pay,
                $refundStream
            ) {
                if ($refund->payNo == $pay->payNo) {
                    $pay->validPayPrice -= $refund->refundPrice;
                    unset($refundStream[$key]);
                }
            });
        });


        // 获取 总有效支付金额流水 [计入实收][含自定义支付]
        $totalPaidInPayPriceValid = $payStream->where('isPaidIn', 1)
                                              ->sum('validPayPrice');

        $extPrice                       = $order->orderExtRel->sum('payPrice');
        $totalPaidInPayPriceValidResult = $totalPaidInPayPriceValid - $extPrice;

        // 判断订单的用户支付金额是否正确
        if ($order->payPrice != $totalPaidInPayPriceValidResult) {
            if ($this->debug) {
                dump(
                    '$orderPayPrice: ' . $order->payPrice,
                    '$totalPaidInPayPriceValid: ' . $totalPaidInPayPriceValid,
                    '$totalPaidInPayPriceValidResult: ' . $totalPaidInPayPriceValidResult
                );
            }
            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_PAY_PRICE_ERROR);
            return;
        }

        // 判断订单的总退款是否正确 - 这个不好改, 暂时不改
        /*  if ($order->refundMoney != $order->orderRefundStreamRel->sum('refundPrice')) {
              if ($this->debug) {
                  dump([
                      'shopId'                       => $order->shopId,
                      'orderId'                      => $order->orderId,
                      'orderRefundMoney'             => $order->refundMoney,
                      'orderRefundStreamRefundPrice' => $order->orderRefundStreamRel->sum('refundPrice')
                  ]);
              }

              $this->insertOrder($order,
                  self::ERROR_REASON_ORDER_REFUND_PRICE_ERROR);
              return;
          }*/

        // 判断优惠券优惠的金额是否完整
        $meituanDiscountTotal = $order->orderCouponExtRel->sum('couponExtDiscountPrice');
        // rms 优惠券
        $rmsDiscountTotal = $order->orderCouponRel->sum('couponDiscountPrice');

        if ($order->couponPrice != $meituanDiscountTotal + $rmsDiscountTotal) {

            if ($this->debug) {
                $total = $meituanDiscountTotal + $rmsDiscountTotal;
                $msg   = [
                    'orderId'           => $order->orderId,
                    'order-couponPrice' => $order->couponPrice,
                    'totalCouponPrice'  => $total,
                    'mt'                => $meituanDiscountTotal,
                    'rms'               => $rmsDiscountTotal
                ];

                $recommended = '';
                if ($order->couponPrice != 0) {
                    if ($order->couponPrice < $meituanDiscountTotal) {
                        $recommended = '推荐把 order_coupon_external 的 couponExtDiscountPrice 总和 修改成' . $order->couponPrice;
                    }
                }
                $msg['recommended'] = $recommended;

                dump($msg);
            }

            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_DISCOUNT_PRICE_ERROR);
            return;
        }

        // 判断优惠券实收金额
        $mtCostPrice  = $order->orderCouponExtRel->sum('couponExtCostPrice');
        $rmsCostPrice = $order->orderCouponRel->sum('couponCostPrice');

        if ($order->couponCostPrice != $mtCostPrice + $rmsCostPrice) {
            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_COST_PRICE_ERROR);
            return;
        }

        // 剔除 套餐
        $dish = $order->orderDetailRel->where('type', 0);

        // 开始判断菜品纬度
        if ($order->originalPrice != $dish->sum('originalPrice')) {
            if ($this->debug) {

                $msg = [
                    'orderId'               => $order->orderId,
                    'order-originalPrice'   => $order->originalPrice,
                    'dish-sumOriginalPrice' => $dish->sum('originalPrice'),
                    'recommended'           => ''
                ];

                if ($dish->sum('originalPrice') > $order->originalPrice) {
                    $recommended = '推荐把 order_detail 的 originalPrice 总和 修改成' . $order->originalPrice;
                } else {
                    $recommended = '推荐把 order 的 originalPrice 修改成' . $dish->sum('originalPrice');

                }
                $msg['recommended'] = $recommended;

                dump($msg);
            }

            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_DETAIL_ORIGIN_PRICE_ERROR);
            return;
        }

        // 判断菜品优惠是否等于订单总优惠
        if ($order->discountPrice != $dish->sum('totalDiscountPrice')) {
            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_DETAIL_DISCOUNT_ERROR);
            return;
        }

        // 判断菜品的实付是否等于支付总实收流水
        if ($dish->sum('payPrice') != $totalPaidInPayPriceValidResult) {
            if ($this->debug) {
                $msg = [
                    'orderId'                   => $order->orderId,
                    '$totalPaidInPayPriceValid' => $totalPaidInPayPriceValidResult,
                    'dish-sumpayPrice'          => $dish->sum('payPrice'),
                    'recommended'               => ''
                ];
                dump($msg);
            }

            $this->insertOrder($order,
                self::ERROR_REASON_ORDER_DETAIL_PAY_PRICE_ERROR);
            return;
        }
    }

    /**
     * 获取最大的门店订单列表
     *
     * @return mixed|null
     */
    public function getMaxOnlineNumShopId()
    {
        $arr = OrderService::arraySort(self::getAllTypeShopList(), 'orderNum');
        return array_shift($arr);
    }

    private function getAllTypeShopList()
    {
        $allTypeShopList = [];
        foreach ($this->shopList as $shop) {
            $allTypeShopList[] = $shop[OrderStatisticalModel::ORDER_STATISTICAL_TYPE_EAT_IN];
        }
        return $allTypeShopList;
    }

    /**
     * 获取最大店铺信息
     *
     * @return mixed|null
     */
    public function getMaxOfflineNumShopId()
    {
        $arr = OrderService::arraySort(self::getAllTypeShopList(), 'offlineOrderNum');
        return array_shift($arr);
    }

    /**
     * 获取店铺信息
     *
     * @param $shopId
     * @param $field
     * @return mixed
     */
    public function getShopField($shopId, string $field = '')
    {
        return $field ? ShopService::getShopInfo($shopId)->$field : ShopService::getShopInfo($shopId);
    }

    public function getOfflineShopNum()
    {
        $i = 0;
        foreach ($this->shopList as $shop) {
            if ($shop[OrderStatisticalModel::ORDER_STATISTICAL_TYPE_EAT_IN]['offlineOrderNum'] > 0) {
                $i++;
            }
        }

        return $i;
    }

    /**
     * 获取飞书发送内容
     *
     * @return string
     */
    public function getFsSendContent()
    {
        return '';
    }

    /**
     * 获取离线模块数据
     *
     * @return string
     */
    public function getFsOffLineShopModule()
    {
        // 离线订单门店列表模块
        $offlineShopList = OrderService::arraySort(self::getAllTypeShopList(), 'offlineOrderNum');

        $str        = <<<STR
离线订单统计
总离线订单量: {$this->num['offlineTotalNum']} 单
总离线店铺数: {$this->num['offlineShopNum']} 家
离线店铺列表: 
STR;
        $recordList = '';

        if (count($offlineShopList) > 0) {
            foreach ($offlineShopList as $offShop) {
                if ($offShop['offlineOrderNum'] == 0) {
                    continue;
                }
                $shopInfo   = $this->getShopField($offShop['shopId']);
                $recordList .= vsprintf(PHP_EOL . "(%s)%s - %s 单",
                    [$shopInfo['shopCode'], $shopInfo['name'], $offShop['offlineOrderNum']]);
            }
        }

        if (empty($recordList)) {
            $recordList = '无';
        }

        return rtrim($str . $recordList, PHP_EOL);
    }

    /**
     * 堂食模块
     *
     * @return string
     */
    public function getFsTsModule()
    {
        return '';
    }
}
